package com.songcan.basics.config;


import com.alibaba.druid.pool.DruidDataSource;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.songcan.common.config.JsonConfiguration;
import com.songcan.common.config.MybatisConfiguration;
import com.songcan.common.config.RedisConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import com.google.code.kaptcha.util.Config;
import javax.sql.DataSource;
import java.util.Properties;

import static com.google.code.kaptcha.Constants.*;

@Component
@Import({MybatisConfiguration.class, JsonConfiguration.class, RedisConfiguration.class})
@MapperScan(basePackages = "com.songcan.basics.*.mapper*")
public class CoreConfig {

    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource(){
        return  new DruidDataSource();
    }


    @Bean
    public DefaultKaptcha defaultKaptcha(){

        Properties properties = new Properties();
        Properties kaptchaProperties = new Properties();
        kaptchaProperties.put("kaptcha.border", "no");
        kaptchaProperties.put("kaptcha.textproducer.char.length","4");
        kaptchaProperties.put("kaptcha.image.height","50");
        kaptchaProperties.put("kaptcha.image.width","150");
        kaptchaProperties.put("kaptcha.obscurificator.impl","com.google.code.kaptcha.impl.ShadowGimpy");
        kaptchaProperties.put("kaptcha.textproducer.font.color","127,255,0");
        kaptchaProperties.put("kaptcha.textproducer.font.size","40");
        kaptchaProperties.put("kaptcha.textproducer.char.string","1234567890");
        kaptchaProperties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
        //kaptchaProperties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.DefaultNoise");
        Config config = new Config(kaptchaProperties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;



    }
}
